package com.feel.easycloud.utils;

import com.feel.easycloud.enums.ApiResultEnum;

import java.io.Serializable;

public class ApiResult<T> implements Serializable {

    private String code;
    private String msg;
    private T data;

    public ApiResult(T data, String code, String msg){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ApiResult success(T data){
        return new ApiResult<T>(data,"0","ok");
    }

    public static <T> ApiResult fail(String code,String msg){
        return new ApiResult<T>(null,code,msg);
    }

    public static <T> ApiResult fail(ApiResultEnum resultEnum){
        return new ApiResult(null,resultEnum.getCode(), resultEnum.getMsg());
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean isOk(){
        return code == "0";
    }

}
